package cn.itsource.pethome.base.service.impl;

import cn.itsource.pethome.base.mapper.BaseMapper;
import cn.itsource.pethome.base.query.BaseQuery;
import cn.itsource.pethome.base.service.IBaseService;
import cn.itsource.pethome.department.domain.Department;
import cn.itsource.pethome.department.mapper.DepartmentMapper;
import cn.itsource.pethome.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;


    @Override
    public List<T> queryAll() {
        return baseMapper.queryAll();
    }

    @Override
    public T queryOne(Long id) {
        return baseMapper.queryOne(id);
    }

    @Override
    public PageList<T> pageQueryAll(BaseQuery query) {
        Long count = baseMapper.count(query);
        PageList<T> pageList = new PageList<>();
        pageList.setTotal(count);
        pageList.setData(baseMapper.pageQueryAll(query));
        return pageList;
    }

    @Transactional
    @Override
    public void insert(T t) {
        baseMapper.insert(t);
    }
    @Transactional
    @Override
    public void update(T t) {
        baseMapper.update(t);
    }
    @Transactional
    @Override
    public void delete(Long id) {
        baseMapper.delete(id);
    }
}
